package com.john.vo;

import com.john.Enum.ResultEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共返回对象格式
 * 日期 2021/5/27 14:46
 * 创建者：john driver
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("固定返回格式")
public class ResultVo {
    @ApiModelProperty("错误码")
    private Integer code;
    @ApiModelProperty("提示信息")
    private String message;
    @ApiModelProperty("响应数据")
    private Object data;

    public static ResultVo success(){
        return new ResultVo(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(),null);
    }

    public static ResultVo success(Object data){
        return new ResultVo(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(),data);
    }
    public static ResultVo error(ResultEnum resultEnum){
        return new ResultVo(resultEnum.getCode(), resultEnum.getMessage(),null);
    }
    public static ResultVo error(ResultEnum resultEnum, Object data) {
        return new ResultVo(resultEnum.getCode(), resultEnum.getMessage(), data);
    }
}
